$(function() {
	$(".select2").select2();
	
	//新建弹出多栏定位
	/*$(".modal").on("click", ".nav.nav-stacked li", function() {
		$(this).addClass("nav_active").siblings().removeClass("nav_active");
	});*/
	
	/**
	 * 给radio和checkbox绑定icheck事件
	 */
	$('input').iCheck({
	    checkboxClass: 'icheckbox_flat-blue',
	    radioClass: 'iradio_flat-blue'
	});
	
	/**
	 * 全选
	 */
	$(".selectAll").on("ifClicked", function() {
		var $operate = $(".operate");
		var $this = $(this);
		var $chks = $this.closest(".px-grid").find('.px-grid-row input[type="checkbox"]');
		if($this.is(":checked")){  //之前没有选中
			for(var i=0; i<$chks.length; i++) {
				$($chks[i]).iCheck('uncheck');
				$operate.slideUp();
			}
		}else{
			for(var i=0; i<$chks.length; i++) {
				$($chks[i]).iCheck('check');
				$operate.slideDown();
			}
		}
	});
	
	/*
	 * 部分选，取消全选
	 */
	$(".selectOne").on("ifClicked", function() {
		var $this = $(this);
		var $selectAll = $(".selectAll");
		var allChks = $this.closest(".px-grid").find('.px-grid-row input[type="checkbox"]').length;  
		var chks = $this.closest(".px-grid").find('.px-grid-row input[type="checkbox"]:checked').length;
		
		if($this.is(":checked")) { //当前是选中
			$selectAll.iCheck("uncheck");	
		}else{
			if(allChks == (chks+1)){
				$selectAll.iCheck("check");
			}else{
				$selectAll.iCheck("uncheck");
			}
		}
	});
	
	/*
	 * 跨页全选， 选择所有数据
	 */
	$(".checkToggle").on("click", function() {
		var $this = $(this);
		if($this.hasClass("single")) {
			$this.removeClass("single");
			$this.html("只选本页数据");
			$(this).closest(".px-grid-cell").find(".checkNum").html("300");
		}else{
			$this.addClass("single");
			$this.html("选择所有数据");
			$(this).closest(".px-grid-cell").find(".checkNum").html("6");
		}
	});
	
	/*
	 * 全屏弹出框，左侧菜单js事件
	 */
	$(".fullScreen-menu").on("click", "ul li:not(:first)", function(){
		$(this).find("i").toggle();
		var index = $(this).index();
		var $content = $(".fullScreen-main-column");
		var count = $content.length;
		for(var i=0; i<count; i++){
			if(i == index){
				$($content[i]).slideToggle();			
			}
		}
	});
	
	/*
	 * 全屏弹出框，右边鼠标事件
	 */
	$(".fullScreen-main").on("mouseover", ".fullScreen-main-column:not(:first)", function() {
		var $this = $(this);
		$this.addClass("on");
		$this.find("i").show();
	}).on("mouseout", ".fullScreen-main-column:not(:first)", function() {
		var $this = $(this);
		$this.removeClass("on");
		$this.find("i").hide();
	});
	
	/**
	 * 全屏弹出框，关闭栏目事件
	 */
	$(".fullScreen-main-column i").click(function() {
		var $content = $(this).closest(".fullScreen-main-column");
	 	var index = $content.index();
	 	var $menu = $(".fullScreen-menu ul li");
		for(var i=0; i<$menu.length; i++){
			if(i == index){
				$($(".fullScreen-menu ul li")[i]).removeClass("on");	
				$($(".fullScreen-menu ul li")[i]).find("i").hide();
			}
		}
		$content.slideUp();
	});
	
	/**
	 * 页面鼠标滚动，固定批量操作按钮和导航
	 */
	var $header = $(".content-header");  //面包屑导航
	var header = $header.offset().top;   //面包导航距离顶部的距离
	var $nav = $(".nav-title");    //面包导航标题
	$(window).scroll(function(){
		var left = $(".main-sidebar").width(); //判断左侧菜单的宽度
		var scrH = $(this).scrollTop();
		var value = 50;
		if(header >= scrH - value) {
			$header.removeClass("px-nav-toolbar");
			if(left == value){
				$nav.removeClass("nav1");  
			}else{
				$nav.removeClass("nav2");
			}
		}else{
			$header.addClass("px-nav-toolbar");
			if(left == value){
				$nav.addClass("nav1");				
			}else{
				$nav.addClass("nav2");
			}
		}
	});
	
	/**
	 * 表单校验
	 */
	$('#userForm').validate({
		 rules:{
		    username : {required : true},
		    userpwd: {required: true},
		    tel: {required: true,isTel:true},
		    phone: {required: true,isMobile:true},
		    code: {required: true,isZipCode:true}
		},
		messages:{
			username : {required : "请输入用户名！"},
		    userpwd : {required : "请输入密码！"},
		    tel: {required: "请输入座机号码！"},
		    phone: {required: "请输入手机号码！"},
		    code: {required: "请输入邮编！"},
		},
		submitHandler: function(form){
		    //ajaxSubmit();  成功之后操作
			layer.msg('校验成功', {
		   		icon: 2,
		   		skin: "skinsuccesscss"
		   	});
    	}
	});
	
	//头部切换向上向下图标
	/*$(".dropdown-toggle").on("click", function() {
		var $icon = $(this).find("i");
		if( $icon.hasClass("icon-xiangxia1") ) {
			$icon.removeClass("icon-xiangxia1").addClass("icon-xiangshang1");
		}else{
			$icon.removeClass("icon-xiangshang1").addClass("icon-xiangxia1");
		}
	});*/
});	